﻿@using DIS.Infrastructure.Entities.Entity;
@{
    ViewBag.Title = "LongHaulFeeDetail";
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<FinancialPeriod> yearmonth = ViewBag.YearMonth;
    User user = ViewBag.User;
    int id=ViewBag.Id!=null?ViewBag.Id:0;
    LongHaul longHaul = ViewBag.longHaul;
    List<LongHaulDetail> longHaulDetails = ViewBag.longHaulDetails;
    
    int longfeeId = longHaul == null ? 0 : longHaul.Id;
    List<Project> projects = ViewBag.projects;
}
<script type="text/javascript">
    function addNew() {
        
        var starts = "";
        $("input[id='start']").each(function () {
            var value = $(this).val();
            starts = starts + value + ",";
        });

        var ends = "";
        $("input[id='end']").each(function () {
            var value = $(this).val();
            ends = ends + value + ",";
        });

        var busdates = "";
        $("input[id='busdate']").each(function () {
            var value = $(this).val();
            busdates = busdates + value + ",";
        });

        var transports = "";
        $("input[id='transport']").each(function () {
            var value = $(this).val();
            transports = transports + value + ",";
        });

        var fees = "";
        $("input[id='fee']").each(function () {
            var value = $(this).val();
            fees = fees + value + ",";
        });

        var invoices = "";
        $("input[id='invoice']").each(function () {
            var value = $(this).val();
            invoices = invoices + value + ",";
        });
         
        $.post("/Reimbursement/AddInfo", { start: starts, end: ends,
            busdate: busdates,
            transport: transports,
            fee: fees,
            invoice: invoices
        }, function (response) {
             
            $("#tbody").html(response.split('^')[0]);
            $("#stotaldays").html(response.split('^')[1]);
            $("#stotalfee").html(response.split('^')[2]);
            $("#stotalcount").html(response.split('^')[3]);
        });
        return false;
    }

    function removeInfo(id) {
        $.post("/Reimbursement/RemoveInfo", { id: id}, function (response) {
            $("#tbody").html(response.split('^')[0]);
            $("#stotaldays").html(response.split('^')[1]);
            $("#stotalfee").html(response.split('^')[2]);
            $("#stotalcount").html(response.split('^')[3]);
        });
        return false;
    }

    function yearMonthSelect() {
        var obj = document.getElementById("selyearmonth");
        var date = obj.options[obj.selectedIndex].value;

        $('#fillDate').html("(" + date.split('$')[1] + ")");
    }
</script>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#D6D6D6">
    <tr>
        <td height="19" background="/content/img/tbg.gif" bgcolor="#E7E7E7">
            <table width="96%" border="0" cellspacing="1" cellpadding="1">
                <tr>
                    <td style="padding-left: 10px;">
                        <b><strong>在途费明细</strong></b>
                    </td>
                    <td align="right">
                        <b><strong><a href="/Reimbursement/LongHaulFee">在途费列表</a></strong></b>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
      
            
    <tr>
        <td bgcolor="#FFFFFF" align="center">
       
           
           
            <table width="90%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#D6D6D6">
                <thead>
                    <tr bgcolor="#FBFCE2" align="center">
                        <td width="15%">
                            起
                        </td>
                        <td width="15%">
                            止
                        </td>
                        <td width="20%">
                            日期
                        </td>
                        <td width="15%">
                            交通工具
                        </td>
                        <td width="10%">
                            在途费用
                        </td>
                        <td width="10%">
                            发票数
                        </td>
                        <td width="5%">
                        </td>
                    </tr>
                </thead>
                <tbody>
                    <tr bgcolor="#FFFFFF" style="align: center">
                        <td>
                            <input name="start" id="start" value="" type="text" style="width: 90%" />
                        </td>
                        <td>
                            <input name="end" id="end" value="" type="text" style="width: 90%" />
                        </td>
                        <td>
                            <input name="busdate" id="busdate" value="" type="text" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})"
                                style="width: 90%" />
                        </td>
                        <td>
                            <input name="transport" id="transport" value="" type="text" style="width: 90%" />
                        </td>
                        <td>
                            <input name="fee" id="fee" value="" type="text" style="width: 90%" />
                        </td>
                        <td>
                            <input name="invoice" id="invoice" value="" type="text" style="width: 90%" />
                        </td>
                        <td>
                            <a href="javascript:;" class="addTr">[+]</a>
                        </td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr>
                        <td bgcolor="#FFFFFF" colspan="7" align="center">
                            <button type="button" value="" onclick="addNew();return false;">
                                添加</button>
                        </td>
                    </tr>
                </tfoot>
            </table>
        </td>
    </tr>
    <form name="saveuserForm" action="/Reimbursement/SaveLongHaulFee" method="post">
       <input type="hidden" id="issubmit" name="state" value="0" />
            <input type="hidden" id="MainId" name="MainId" value="@longfeeId" />   
         <tr height="30px">
                    <td colspan="7" align="left">
                        <strong>在途费用记录</strong>&nbsp;&nbsp;<select name="selyearmonth" id="selyearmonth" onchange="yearMonthSelect()">
                            <option value="无">请选择</option>
                            @{
                                string filldate = "";
                                if (yearmonth != null && yearmonth.Any())
                                {
                                    foreach (var item in yearmonth)
                                    {
                                        string sdateStr = DateTime.Parse(item.StartDate).ToString("yyyy年MM月dd日");
                                        string edateStr = DateTime.Parse(item.EndDate).ToString("yyyy年MM月dd日");

                                        if (longHaul != null && longHaul.Year == item.Year && longHaul.Month == item.Month)
                                        {
                                            filldate = "(" + sdateStr + "-" + edateStr + ")";
                                <option value="@(item.Year):@(item.Month):@(item.StartDate):@(item.EndDate)$@(sdateStr)-@(edateStr)" selected>@item.Year-@item.Month</option>
                                        }
                                        else
                                        {
                                <option value="@(item.Year):@(item.Month):@(item.StartDate):@(item.EndDate)$@(sdateStr)-@(edateStr)">@item.Year-@item.Month</option>
                                        }
                                    }
                                }
                            }
                        </select><span id="fillDate">@filldate</span>&nbsp;&nbsp;&nbsp;&nbsp;
                        <strong>项目名称</strong>&nbsp;&nbsp;<select name="projectId" id="projectId">
                        <option value="0">请选择</option>
                        @{
                            if(projects!=null&&projects.Count>0)
                            {
                                foreach(var item in projects)
                                {
                                    if (longHaul != null && longHaul.project.Id == item.Id)
                                    {
                                        <option value="@item.Id" selected>@item.ProjectCode (@item.ProjectName)</option>
                                    }
                                    else
                                    {
                                    <option value="@item.Id">@item.ProjectCode (@item.ProjectName)</option>
                                    }
                                }
                            }
                        }
                        </select>
                    </td>
                </tr>
    <tr>
        <td>
            <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
                <thead>
                    <tr bgcolor="#FBFCE2">
                        <td width="10%" align="center" rowspan="2">
                            姓名
                        </td>
                        <td width="30%" align="center" colspan="2">
                            行程
                        </td>
                        <td width="15%" align="center" rowspan="2">
                            日期
                        </td>
                        <td width="10%" align="center" rowspan="2">
                            出差天数
                        </td>
                        <td width="10%" align="center" rowspan="2">
                            交通工具
                        </td>
                        <td width="10%" align="center" rowspan="2">
                            在途费用
                        </td>
                        <td width="10%" align="center" rowspan="2">
                            发票数
                        </td>
                        <td width="5%" align="center" rowspan="2">
                        </td>
                    </tr>
                    <tr bgcolor="#FBFCE2">
                        <td width="15%" align="center">
                            起
                        </td>
                        <td width="15%" align="center">
                            止
                        </td>
                    </tr>
                </thead>
                <tbody id="tbody">
                @Html.Raw(ViewBag.tbody)
                </tbody>
                <tfoot>
                    <tr bgcolor="#FBFCE2">
                        <td width="10%" align="center">
                            合计
                        </td>
                        <td width="15%">
                            &nbsp;
                        </td>
                        <td width="15%">
                            &nbsp;
                        </td>
                        <td width="10%">
                            &nbsp;
                        </td>
                        <td width="10%" align="center">
                         @{
                             if (longHaul != null)
                             {
                                 <span name="stotaldays" id="stotaldays" value="@longHaul.TotalDays">@longHaul.TotalDays</span>
                             }
                             else
                             {
                                 <span name="stotaldays" id="stotaldays" value="0">0</span>
                             }
                         }
                            
                        </td>
                        <td width="10%">
                            &nbsp;
                        </td>
                        <td width="10%" align="center">
                        @{
                            if (longHaul != null)
                            {
                                 <span name="stotalfee" id="stotalfee" value="@longHaul.TotalFee">@longHaul.TotalFee</span>
                            }
                            else
                            {
                                 <span name="stotalfee" id="stotalfee" value="0">0.00</span>
                            }
                         } 
                        </td>
                        <td width="10%" align="center">
                         @{
                             if (longHaul != null)
                             {
                                 <span name="stotalcount" id="stotalcount" value="@longHaul.InvoiceCount">@longHaul.InvoiceCount</span>
                             }
                             else
                             {
                                 <span name="stotalcount" id="stotalcount" value="0">0</span>
                             }
                         } 
                        </td>
                        <td width="5%">
                            &nbsp;
                        </td>
                    </tr>
                </tfoot>
            </table>
        </td>
    </tr>
     <tr>
        <td align="center">
            <input class="new_save" value="保存" type="Submit" />
            <input class="new_submit" value="提交" type="Submit" />
        </td>
    </tr>
    </form>
</table>
@section tail{
    <script type="text/javascript">
        $('.addTr').live('click', function () {

            str = $(this).parent().parent().html();
            str = str.replace('addTr', 'removeTr');
            str = str.replace('[+]', '[-]');
            //str = $("#moban").html();
            $(this).parent().parent().parent().append('<tr  bgcolor="#FFFFFF">' + str + '</tr>');
            // $(this).parent().parent().parent().append(str);
            feesum();
            invoicesum();
        });

        $('.removeTr').live('click', function () {
            $(this).parent().parent().remove();
            feesum();
            invoicesum();
            return false;
        });
        $('.new_save').click(function () {
            $('#issubmit').attr('value', 0);
            return true;
        });
        $('.new_submit').click(function () {
            $('#issubmit').attr('value', 1);
            return true;
        });
        
    </script>
}
